<template>
   
  <div class="app-container">
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button
          style="float: right"
          @click="searchGiftsCategoryList()"
          type="primary"
          size="small"
        >
          查询结果
        </el-button>
        <el-button
          style="float: right; margin-right: 15px"
          @click="handleResetSearch()"
          size="small"
        >
          重置
        </el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form
          :inline="true"
          :model="listQuery"
          size="small"
          label-width="120px"
        >
          <el-form-item label="商品名称：">
            <el-input
              style="width: 203px"
              v-model="listQuery.productName"
              placeholder="商品名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="评价：">
            <el-select v-model="listQuery.starStr">
              <el-option :value="'4,5'" label="好评"></el-option>
              <el-option :value="'2,3'" label="中评"></el-option>
              <el-option :value="'1'" label="差评"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
    </el-card>
    <div class="table-container">
      <!-- @selection-change="handleSelectionChange" -->
      <el-table
        ref="giftsCategoryTable"
        :data="list"
        style="width: 100%"
        
        v-loading="listLoading"
        border
      >
        <!-- <el-table-column
          type="selection"
          width="60"
          align="center"
        ></el-table-column> -->

        <el-table-column prop="id" label="编号" align="center">
          <template slot-scope="scope">
            {{ scope.row.id }}
          </template>
        </el-table-column>
 
        <el-table-column label="用户昵称" align="center">
          <template slot-scope="scope">{{ scope.row.memberNickName }}</template>
        </el-table-column>
        <!-- <el-table-column label="用户电话" align="center">
                    <template slot-scope="scope">{{scope.row.memberName}}</template>
                </el-table-column> -->

        <el-table-column label="商品名称" align="center">
          <template slot-scope="scope">{{ scope.row.productName }}</template>
        </el-table-column>

        <el-table-column label="评价" align="center">
          <template slot-scope="scope">{{
            scope.row.star | formatStar
          }}</template>
        </el-table-column>
        <el-table-column label="评论内容" align="center">
          <template slot-scope="scope">{{ scope.row.content }}</template>
        </el-table-column>
        <el-table-column label="图片" align="center">
          <template slot-scope="scope">
            <!-- <el-image
              :src="scope.row.pics[0]"
              lazy
              :preview-src-list="scope.row.pics"
            ></el-image> -->
            <el-popover
              placement="right"
              width="400"
              trigger="click"
              v-if="scope.row.pics"
            >
              <div
                class="demo-image__lazy"
                style="
                  
                  max-height: 600px;
                  overflow-y: scroll;
                  background: #fff;
                "
              >
                <el-image
                  v-for="url in scope.row.pics.split(',')"
                  :key="url"
                  :src="url"
                  style="width: 100%;margin-bottom:6px;"
                ></el-image>
              </div>
              <el-button slot="reference">查看</el-button>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="评论时间" align="center">
          <template slot-scope="scope">{{
            scope.row.createTime | formatCreateTime
          }}</template>
        </el-table-column>
        <el-table-column label="回复内容" align="center">
          <template slot-scope="scope">{{ scope.row.replayContent }}</template>
        </el-table-column>
        <el-table-column label="回复时间" align="center">
          <template slot-scope="scope">{{
            scope.row.replayCreateTime | formatCreateTime
          }}</template>
        </el-table-column>

        <el-table-column label="操作" align="center" fixed="right" width="170">
          <template slot-scope="scope">
            <el-button
              v-if="!scope.row.replayContent && storeId > 0"
              size="mini"
              type="primary"
              @click="handleReply(scope.$index, scope.row)"
              >回复
            </el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="batch-operate-container"></div>
    <el-dialog title="回复评论" :visible.sync="dialog">
      <el-form v-model="form" ref="form">
        <el-form-item prop="replyContent">
          <el-input
            v-model="form.content"
            placeholder="请输入评论内容"
            type="textarea"
            :rows="6"
          ></el-input>
        </el-form-item>
        <el-form-item style="text-align: right">
          <el-button @click="dialog = false">取 消</el-button>
          <el-button type="primary" @click="replyApi">确 定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :page-size="listQuery.pageSize"
        :page-sizes="[10, 15, 50]"
        :current-page.sync="listQuery.pageNum"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import {
  fetchList,
  createReplays,
  deleteGifts,
} from "@/api/pms/productConsult";
import { formatDate } from "@/utils/date";
const defaultListQuery = {
  pageNum: 1,
  productName: null,
  pageSize: 10,
  starStr: null,
};
export default {
  name: "giftsCategoryList",
  data() {
    return {
      form: {
        content: "",
        commentId: "",
      },
      dialog: false,
      operateType: null,
      listQuery: Object.assign({}, defaultListQuery),
      list: null,
      total: null,
      listLoading: true,
      multipleSelection: [],
      storeId: null,
      selectProductCateValue: null,
    };
  },
  created() {
    this.getList();
    this.storeId = this.$store.state.user.storeId;
  },
 
  filters: {
    formatCreateTime(time) {
      if (time) {
        let date = new Date(time);
        return formatDate(date, "yyyy-MM-dd hh:mm:ss");
      }
    },
    formatStar(value) {
      if (value === 1) {
        return "差评";
      } else if (value === 2) {
        return "中评";
      } else if (value === 3) {
        return "中评";
      } else if (value === 4) {
        return "好评";
      } else if (value === 5) {
        return "好评";
      }
    },
    formatComment(value) {
      if (value == "好评") {
        return "4,5";
      } else if (value == "中评") {
        return "2,3";
      } else if (value == "差评") {
        return "1";
      }
    },
  },
  methods: {
    handleResetSearch() {
      this.listQuery = Object.assign({}, defaultListQuery);
    },
    // 回复
    handleReply(index, row) {
      this.dialog = true;
      this.form.commentId = row.id;
    },
    replyApi() {
      if (this.form.content == "") {
        this.$message.error("请输入评论内容");
        return;
      }
      createReplays(this.form).then((res) => {
        this.$message.success(res.data);
        this.form.content = "";
        this.dialog = false;
        this.getList();
      });
    },
    getList() {
      this.listLoading = true;
      console.log(this.listQuery);
      fetchList(this.listQuery).then((response) => {
        this.listLoading = false;
        this.list = response.data;
        // this.list = response.data.records;
        // this.total = response.data.total;
        // this.totalPage = response.data.pages;
        // this.pageSize = response.data.size;
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    handleDelete(index, row) {
      this.$confirm("是否要删除该评论", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        deleteGifts(row.id).then((response) => {
          this.$message({
            message: "删除成功",
            type: "success",
            duration: 1000,
          });
          this.getList();
        });
      });
    },
    getProductList(index, row) {
      console.log(index, row);
    },
    getProductCommentList(index, row) {
      console.log(index, row);
    },

    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },
    searchGiftsCategoryList() {
      this.listQuery.pageNum = 1;
      this.getList();
    },
    handleBatchOperate() {
      console.log(this.multipleSelection);
      if (this.multipleSelection < 1) {
        this.$message({
          message: "请选择一条记录",
          type: "warning",
          duration: 1000,
        });
        return;
      }
      let showStatus = 0;
      if (this.operateType === "showGiftsCategory") {
        showStatus = 1;
      } else if (this.operateType === "hideGiftsCategory") {
        showStatus = 0;
      } else {
        this.$message({
          message: "请选择批量操作类型",
          type: "warning",
          duration: 1000,
        });
        return;
      }
      let ids = [];
      for (let i = 0; i < this.multipleSelection.length; i++) {
        ids.push(this.multipleSelection[i].id);
      }
      let data = new URLSearchParams();
      data.append("ids", ids);
      data.append("showStatus", showStatus);
      updateShowStatus(data).then((response) => {
        this.getList();
        this.$message({
          message: "修改成功",
          type: "success",
          duration: 1000,
        });
      });
    },
    addGiftsCategory() {
      this.$router.push({ path: "/pms/addPmsGiftsCategory" });
    },
  },
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>


